<?php
ob_start();
include("dbinfo.inc.php");
mysql_connect(localhost,$username,$password);
@mysql_select_db($database) or die( "Unable to select database"); 

$query="select ID from Account where userName like '$_POST[userName]';";
$resultID=mysql_query($query);
if (!$resultID) {
  echo "Error selecting ID from Account: " . mysql_error();
  die("");
}
$userID=mysql_result($result,0, "ID");

$query="
DELETE FROM Account WHERE userName like '$_POST[userName]';
";
if (!mysql_query($query)) {
  echo "Error deleting entry from TrailHead: " . mysql_error();
}

$query="
INSERT INTO Account
VALUES (
	$userID,
	'$_POST[userName]', 
	MD5('$_POST[password]'), 
	'$_POST[firstName]', 
	'$_POST[lastName]', 
	'$_POST[city]', 
	'$_POST[state]', 
	'$_POST[DOB]', 
	'$_POST[sex]', 
	'$_POST[bio]',
	'$_POST[photo]'
)";

if (!mysql_query($query)) {
  echo "Error inserting entry into Account: " . mysql_error();
}

mysql_close();
header("Location: index.php");
ob_flush();
?> 
